﻿/// <reference path="~/Scripts/FlowBasis/FlowBasis-all-vsdoc.js" />

if (typeof window["FlowBasis"] == "undefined") {
    FlowBasis = {};
    FlowBasis.__namespace = true;
}

FlowBasis.defineNamespace = function (namespace) {
    /// <summary>
    /// Setup a namespace within FlowBasis hierarchy if it is not already defined.
    /// </summary>
    var parts = namespace.split('.');
    var current = FlowBasis;
    for (var i = 0; i < parts.length; i++) {
        var part = parts[i];
        if (current[part]) {
            current = current[part];
        }
        else {
            var newNamespace = {};
            newNamespace.__namespace = true;
            current[part] = newNamespace;
            current = newNamespace;
        }
    }
};


FlowBasis.resolveUrl = function (url) {
    /// <summary>
    /// If url starts with "~/", this will convert site relative url to server relative. Otherwise, it 
    /// returns the original url. FlowBasis.Paths.siteRoot should contain a trailing slash.
    /// </summary>

    if (url && url.length >= 2 && url[0] == '~' && url[1] == '/') {        
        if (url.length == 2) {
            return FlowBasis.Paths.siteRoot;
        }
        else {
            return FlowBasis.Paths.siteRoot + url.substr(2);
        }        
    }

    return url;
};